// 汉中库得网络科技版权所有
#include "BBGameInstance.h"

#include "Db.h"
#include "Record.h"
DEFINE_LOG_CATEGORY(LogBuildingBlock);

UBBGameInstance::UBBGameInstance(){
	UDb::Config(TEXT("SQLiteDBs/UserData.db"));
}

bool UBBGameInstance::GetIsUnlocked() const{
	if(CurrentLevel == "level1"){
		return true;
	}
	int32 LevelCount = 0;
	GetCurrentLevel(LevelCount);
	LevelCount--;
	const FString TempLevel = "level" + FString::FromInt(LevelCount);
	const URecord* Record = UDb::FindById("LevelRecord", "level", TempLevel);
	
	bool Result;
	if(Record != nullptr){
		Result = true;
	} else{
		Result = false;
	}
	return Result;
}

void UBBGameInstance::SetCurrentLevel(FName Level){
	CurrentLevel = Level;
}

FName UBBGameInstance::GetCurrentLevel(int32& LevelCount) const{
	if(CurrentLevel != "None"){
		FString LevelStr = CurrentLevel.ToString();
		LevelStr = LevelStr.Replace(TEXT("level"), TEXT(""));
		LevelCount = FCString::Atod(*LevelStr);
	}
	return CurrentLevel;
}
